package com.yswy.domain.entity.tf;

import com.alibaba.nacos.common.util.Md5Utils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yswy.domain.vo.dto.TgDevice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.zip.CRC32;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Api(tags = "推广回传记录表（巨量）")
@TableName(value = "tg_call_back_jl_id")
public class TgCallBackJlId {
    @TableId(type = IdType.AUTO)
    private Long id;
    @ApiModelProperty("回调type")
    private Integer activeType;
    @ApiModelProperty("渠道")
    private String channel;
    @ApiModelProperty("渠道包")
    private String packChannel;
    @ApiModelProperty("项目ID")
    private Long projectId;
    @ApiModelProperty("广告主id/账户id")
    private String advertuserid;
    @ApiModelProperty("广告投放位置")
    private String csite ;
    @ApiModelProperty("转化id")
    private String convertid;
    @ApiModelProperty("安卓的设备 ID 的 md5 摘要，32位")
    private String imei;
    @ApiModelProperty("安卓id原值的md5，32位")
    private String android;
    @ApiModelProperty("Android Q及更高版本的设备号，常见32位")
    private String oaid;
    @ApiModelProperty("一些跟广告信息相关的回调参数，内容是一个加密字符串，在调用事件回传接口的时候会用到")
    private String callbackparam;
    @ApiModelProperty("一些跟广告信息相关的回调参数，内容是一个加密字符串，在调用事件回传接口的时候会用到")
    private String callbackparammd5;
    @ApiModelProperty("一些跟广告信息相关的回调参数，内容是一个加密字符串，在调用事件回传接口的时候会用到")
    private Long callbackparamCrc;
    @ApiModelProperty("操作系统平台")
    private String osid;
    @ApiModelProperty("移动设备mac地址,转换成大写字母,去掉“:”，并且取md5摘要后的结果")
    private String mac;
    @ApiModelProperty("ip")
    private String channelip;
    @ApiModelProperty("手机型号")
    private String model;
    @ApiModelProperty("手机型号+Ip 用于模糊匹配用户")
    private String modelIp;
    @ApiModelProperty("创建时间")
    private Date createTime;


    public TgCallBackJlId(String channel ,String packChannel ,Long projectId , TgDevice tgDevice , Integer activeType ) {
        this.channel = channel;
        this.packChannel = packChannel;
        this.projectId = projectId;
        this.activeType = activeType;
        this.advertuserid = tgDevice.getADVERTISER_ID();
        this.csite = tgDevice.getCSITE();
        this.convertid = tgDevice.getCONVERT_ID();
        this.imei = tgDevice.getIMEI();
        this.android = tgDevice.getANDROIDID();
        this.oaid = tgDevice.getOAID().replaceAll("\\s" , "");
        this.callbackparam = tgDevice.getCALLBACK_PARAM();
        this.callbackparammd5 = Md5Utils.getMD5(tgDevice.getCALLBACK_PARAM() , "UTF-8");
        CRC32 crc32 = new CRC32();
        crc32.update(tgDevice.getCALLBACK_PARAM().getBytes());
        this.callbackparamCrc = crc32.getValue();
        this.osid = tgDevice.getOS();
        this.mac = tgDevice.getMAC();
        this.channelip = tgDevice.getIP();
        this.model = tgDevice.getMODEL();
        this.createTime = new Date();
        this.modelIp=tgDevice.getMODEL().replaceAll("\\s" , "")+tgDevice.getIP();

    }


    public static void main(String[] args) {
        CRC32 crc32 = new CRC32();
        crc32.update("c.rqB7I6enkYhGUseoWmFQtifecPLHpOOe7BRx0jOyNqXj7D16SjahWOiMzZsC7rKngpJJeoTQt3JZeLYf9ejgDqesRTRqR34memQ4RNFfa7TnkfPfXffyj1nypdVoSA7Yoms12ZPVyWM8J8HKDLuYgtJE".getBytes());
        System.out.println(crc32.getValue());
    }

}
